﻿using Anke.SHManage.MSSQLDAL;
using Anke.SHManage.MSSQLDAL.TJDAL;
using Microsoft.Reporting.WebForms;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Anke.SHManage.Web.Reports
{
    public partial class TJ_PatientChargeModeWebForm : System.Web.UI.Page
    {
        private string reportName;
        protected void Page_Load(object sender, EventArgs e)
        {


            if (!IsPostBack)
            {
                InitPage();
            }
            else
            {
                reportName = Convert.ToString(ViewState["reportName"]);
            }
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindReportDataSource();

        }
        private void InitPage()
        {
            this.StartDate.Text = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd 07:30:00");
            this.EndDate.Text = DateTime.Now.ToString("yyyy-MM-dd 07:30:00");
            reportName = Request.QueryString["ReportName"];
            ViewState["reportName"] = reportName;

            BindReportDataSource();
        }
        protected void BindReportDataSource()
        {
            DateTime beginTime = Convert.ToDateTime(this.StartDate.Text);
            DateTime endTime = Convert.ToDateTime(this.EndDate.Text);
            string eventType = Convert.ToString(this.txtPatientVersion.Text);
            string txtCenter = Convert.ToString(this.Center.Text);
            string stationID = Convert.ToString(this.Station.Text);
            string agentID = Convert.ToString(this.txtAgentWorkID.Text);
            string doctorAndNurse = Convert.ToString(this.txtDoctorAndNurse.Text);
            string txtDiseasesClassification = Convert.ToString(this.txtDiseasesClassification.Text);
            string txtIllnessClassification = Convert.ToString(this.txtIllnessClassification.Text);
            string txtDeathCase = Convert.ToString(this.txtDeathCase.Text);
            string txtFirstAidEffect = Convert.ToString(this.txtFirstAidEffect.Text);
            string txtFirstImpression = Convert.ToString(this.txtFirstImpression.Text);
            string IFNormalEnd = Convert.ToString(this.IFNormalEnd.Text);
            string OrderByWay = Convert.ToString(this.OrderByWay.Text) +"  "+ Convert.ToString(this.upDown.Text) == "  "  ? "PaidMoney desc" : Convert.ToString(this.OrderByWay.Text) +"  "+ Convert.ToString(this.upDown.Text);
          
            if (OrderByWay == "  desc") { OrderByWay = " PaidMoney desc "; }
            string StretcherBearersI = Convert.ToString(this.StretcherBearersI.Text);
            string Driver = Convert.ToString(this.Driver.Text);
            string DriverWC = Convert.ToString(this.DriverWC.Text);
            string DoctorWC = Convert.ToString(this.DoctorWC.Text);
            string StretcherBearersWC = Convert.ToString(this.StretcherBearersWC.Text);

            //add2021-10-15 plq 医保上线移植，新增收费方式、支付宝微信支付、是否医保时间 三条件 start
            int chargeType = -1;
            if (this.ChargeType.Text != "")
                chargeType = Convert.ToInt32(this.ChargeType.Text); //20171128 yh 收费方式
            string IFAccountCheck = Convert.ToString(this.IFAccountCheck.Text); //2020-05-14 zch --只用于流水表
            int IFYiBaoTime = Convert.ToInt32(this.RadioButtonList_IFYiBaoTime.SelectedValue);//20210701gdg--是否医保时间查询
            //医保上线移植，新增收费方式、支付宝微信支付、是否医保时间 三条件 end

            string start1 = beginTime.ToString();
            string end1 = endTime.ToString();


            this.ReportViewer1.LocalReport.DataSources.Clear();
            this.ReportViewer1.LocalReport.ReportPath = Server.MapPath(@"~/Reports/"+ reportName);
            Microsoft.Reporting.WebForms.ReportParameter st = new Microsoft.Reporting.WebForms.ReportParameter("StartTime", start1);
            Microsoft.Reporting.WebForms.ReportParameter ed = new Microsoft.Reporting.WebForms.ReportParameter("EndTime", end1);
            this.ReportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WebForms.ReportParameter[] { st, ed });
            TJDAL dal = new TJDAL();
            LSDAL lsdal = new LSDAL();

            Label_IFYiBaoTime.Visible = false;//20210701 //add2021-10-15 plq 医保上线移植
            RadioButtonList_IFYiBaoTime.Visible = false;//20210701 //add2021-10-15 plq 医保上线移植
            switch (reportName)
            {
                case "TJ_PatientCharge.rdlc":
                    this.Page.Title = "收费统计表";
                    //this.OrderByWay.Enabled = false;//20210624--gdg禁用
                    DataTable dttj = dal.Get_TJ_PatientCharge(beginTime, endTime, eventType, stationID, agentID, doctorAndNurse,
                  txtCenter, txtDiseasesClassification, txtIllnessClassification, txtDeathCase, txtFirstAidEffect,
                  txtFirstImpression, IFNormalEnd, OrderByWay, StretcherBearersI, Driver, DriverWC, DoctorWC, StretcherBearersWC, chargeType, IFAccountCheck);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForPatientCharge", dttj));
                    break;
                case "LS_PatientCharge.rdlc":
                    this.Page.Title = "收费流水表";
                    this.orderType.Visible = false;
                    this.upordown.Visible = false;
                    this.OrderByWay.Visible = false;
                    this.upDown.Visible = false;
                    LabelZhiFuBaoWXSFSH.Text = "微信支付宝审核：";//20210626 //add2021-10-15 plq 医保上线移植
                    Label_IFYiBaoTime.Visible = true;//20210701
                    RadioButtonList_IFYiBaoTime.Visible = true;//20210701
                    DataTable dtls = lsdal.Get_LS_PatientCharge(beginTime, endTime, eventType, stationID, agentID, doctorAndNurse,
      txtCenter, txtDiseasesClassification, txtIllnessClassification, txtDeathCase, txtFirstAidEffect,
      txtFirstImpression, IFNormalEnd, OrderByWay, StretcherBearersI, Driver, DriverWC, DoctorWC, StretcherBearersWC, chargeType, IFAccountCheck, IFYiBaoTime);
                    this.ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSetForLSPatientCharge", dtls));
                    break;
                default:
                    break;
            }
            this.ReportViewer1.LocalReport.Refresh();
        }

    }
}